package com.tanhua.model.vo;

import com.tanhua.model.mongo.Questions;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class QuestionsVo {

    private String id; // String类型， 问题编号
    private String question; // 问题名称

    private List<AnswerVo> options;

    // 封装问题和问题所有的答案
    public static QuestionsVo init(Questions questions, List<AnswerVo> options) {
        QuestionsVo vo = new QuestionsVo();
        vo.setId(questions.getQuestionId().toString());
        vo.setQuestion(questions.getQuestionName());
        for (AnswerVo answer : options) {
            AnswerVo answerVo = new AnswerVo();
            if(answer != null){
                answerVo.setId(answer.getId());
                answerVo.setOption(answer.getOption());
            }
        }
        vo.options = options;
        return vo;
    }

}
